package com.fenxiangle.yueding.common.widget.popupwindow;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.fenxiangle.yueding.R;

import cn.bingoogolapple.progressbar.BGAProgressBar;

public class PopupWindowProgress extends PopupWindow {

    private LayoutInflater inflater = null;
    private Activity mActivity;
    public PopupWindowProgress(Activity activity) {
        this.mActivity = activity;
        inflater = LayoutInflater.from(mActivity);
    }
    BGAProgressBar tvFirst;
     PopupWindow popupWindow;
    private int[] color={R.color.alpha_gray};
    @SuppressLint("WrongConstant")
    public void showMoreWindow() {
        final RelativeLayout layout = (RelativeLayout) LayoutInflater.from(mActivity).inflate(R.layout.popup_progress, null);

        //初始化一个PopupWindow，width和height都是WRAP_CONTENT
        popupWindow = new PopupWindow(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        //设置PopupWindow的视图内容
        popupWindow.setContentView(layout);

        popupWindow.setFocusable(true);//弹出键盘
        //键盘弹出会遮住输入框
        popupWindow.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
        popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

        DisplayMetrics dm = new DisplayMetrics();
        mActivity.getWindowManager().getDefaultDisplay().getMetrics(dm);
        popupWindow.getContentView().measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        popupWindow.setHeight(popupWindow.getContentView().getMeasuredHeight());

        WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();
        lp.alpha = 0.4f;
        mActivity.getWindow().setAttributes(lp);



         tvFirst=layout.findViewById(R.id.circle_progress_bar3);

        //点击空白区域PopupWindow消失，这里必须先设置setBackgroundDrawable，否则点击无反应
        popupWindow.setBackgroundDrawable(new ColorDrawable(0x00000000));
        popupWindow.setOutsideTouchable(true);
        //设置PopupWindow动画
        popupWindow.setAnimationStyle(R.style.PopupWindow);
        //设置是否允许PopupWindow的范围超过屏幕范围
        popupWindow.setClippingEnabled(true);
        //设置PopupWindow消失监听
        popupWindow.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();
                lp.alpha = 1f;
                mActivity.getWindow().setAttributes(lp);
            }
        });
        int[] location = new int[2];

        //PopupWindow在targetView下方弹出


    }

    public void setShow(View anchor){
        popupWindow.showAtLocation(anchor, Gravity.LEFT | Gravity.CENTER, 0, 0);
    }

    public void dismiss(){
        popupWindow.dismiss();
    }

    public void setTvFirst(float Progress){
        tvFirst.setProgress((int) Progress);
    }
}
